<?php
namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "game_states".
 *
 * @property integer $state_id
 * @property string $state_name
 * @property string $game_count
 * @property string $alias
 */
class GameState extends \yii\db\ActiveRecord
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'game_states';
    }

    /**
     * 产生创建日期和更新日期时间戳
     */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'created_at',
                'updatedAtAttribute' => 'updated_at'
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [
                [
                    'state_name',
                    'alias'
                ],
                'required'
            ],
            [
                [
                    'game_count'
                ],
                'integer'
            ],
            [
                [
                    'state_name',
                    'alias'
                ],
                'string',
                'max' => 50
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'state_id' => '状态ID',
            'state_name' => '状态名称',
            'game_count' => '游戏数量',
            'alias' => '别名',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At'
        ];
    }

    // relationship
    /**
     * 一个状态下的游戏
     */
    public function getGames()
    {
        return $this->hasMany(Game::className(), [
            'state_id' => 'state_id'
        ]);
    }
}
